import { Global, Module, OnApplicationBootstrap } from "@nestjs/common";
import { TypeOrmModule } from "@nestjs/typeorm";
import { DbService, DbEntityList } from "./db.service";
import { SeedService } from "./seed.service";

@Global()
@Module({
  imports: [TypeOrmModule.forFeature([...DbEntityList])],
  providers: [DbService, SeedService],
  exports: [DbService],
})
export class DbModule implements OnApplicationBootstrap {
  constructor(private readonly seedService: SeedService) {}

  async onApplicationBootstrap() {
    await this.seedService.seed();
  }
}
